//
//  CompanyIntroViewController.m
//  CYWFrame
//
//  Created by 于顺燊 on 2018/9/21.
//  Copyright © 2018年 Macx. All rights reserved.
//

#import "CompanyIntroViewController.h"
#import "CompanyInfo.h"
#import <UIButton+WebCache.h>

@interface CompanyIntroViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,UITextFieldDelegate, UITextViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource>

@property (nonatomic, assign) NSInteger imgTag;		//点了哪个按钮添加图片
@property (nonatomic, assign) NSInteger imgIndex;	//要替换图片数组里的哪个下标
@property (nonatomic, strong) NSMutableArray *imgStrArr;
@property (nonatomic, strong) UIImagePickerController *picker; // 照相机

@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIView *pickerBgView;
@property (strong, nonatomic) UIView *pickerToolbgView;

@property (strong, nonatomic) NSArray *phaseInfoArr;
@property (strong, nonatomic) NSArray *companySizeInfoArr;
@property (strong, nonatomic) NSArray *fieldInfoArr;

@property (strong, nonatomic) UIPickerView *phasePicker;
@property (strong, nonatomic) UIPickerView *companySizePicker;
@property (strong, nonatomic) UIPickerView *fieldPicker;

@property (strong, nonatomic) UIButton *logo;
@property (strong, nonatomic) UITextField *companyNameTF;
@property (strong, nonatomic) UITextField *companySizeTF;
@property (strong, nonatomic) UITextField *fieldTF;
@property (strong, nonatomic) UITextField *phaseTF;
@property (strong, nonatomic) UITextView *addressTV;
@property (strong, nonatomic) UITextView *companyIntroTV;
@property (strong, nonatomic) UITextView *advantageTV;
@property (strong, nonatomic) UITextView *bossTV;
@property (strong, nonatomic) UIImageView *teamImgBtn;

@property (strong, nonatomic) CompanyInfo *model;

@end

@implementation CompanyIntroViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	[self createImgPicker];
	[self getCompanyInfo];
	[self createUI];
    // Do any additional setup after loading the view.
}

- (void)createUI {
	self.view.backgroundColor = UISeparatedColorRGB;
	self.navigationItem.title = @"企业介绍";
	_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
	[self.view addSubview:_scrollView];
	NSArray *arr = [NSArray arrayWithObjects:@"   公司logo*", @"   公司名称*", @"   公司规模*", @"   行业领域*", @"   发展阶段*", @"   公司地址*", @"   公司简介*", @"   公司优势*", @"   Boss亮点*", @"   团队风采*", nil];
	
	CGSize size = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(15)];
	
	for (int i = 0; i < arr.count; i++) {
		UILabel *label = [[UILabel alloc] init];
		[_scrollView addSubview:label];
		label = [self createLabel:label text:arr[i]];
		label.tag = 1+i;
	}
	
	UILabel *logoL = [self.view viewWithTag:1];
	logoL.frame = CGRectMake(0, 0, SCREEN_WIDTH, size.height+30);
	_logo = [UIButton buttonWithType:UIButtonTypeCustom];
	[_scrollView addSubview:_logo];
	_logo.frame = CGRectMake(SCREEN_WIDTH-SW(20)-20-size.height, 5,  20+size.height,  20+size.height);
	//_logo.layer.cornerRadius = (20+size.height)/2;
	_logo.layer.masksToBounds = YES;
	[_logo setBackgroundImage:IMAGE(@"com_add_logo") forState:UIControlStateNormal];
	_logo.tag = 21;
	[_logo addTarget:self action:@selector(picAction:) forControlEvents:UIControlEventTouchUpInside];
	
	UILabel *companyNameL = [self.view viewWithTag:2];
	companyNameL.frame = CGRectMake(0, logoL.y+logoL.height+1, SCREEN_WIDTH, size.height+30);
	_companyNameTF = [self createTextFieldWith:companyNameL tag:22 pickerNum:0];
	
	UILabel *companySizeL = [self.view viewWithTag:3];
	companySizeL.frame = CGRectMake(0, companyNameL.y+companyNameL.height+1, SCREEN_WIDTH, size.height+30);
	_companySizeTF = [self createTextFieldWith:companySizeL tag:23 pickerNum:3];
	
	UILabel *fieldL = [self.view viewWithTag:4];
	fieldL.frame = CGRectMake(0, companySizeL.y+companySizeL.height+1, SCREEN_WIDTH, size.height+30);
	_fieldTF = [self createTextFieldWith:fieldL tag:24 pickerNum:0];
	
	UILabel *phaseL = [self.view viewWithTag:5];
	phaseL.frame = CGRectMake(0, fieldL.y+fieldL.height+1, SCREEN_WIDTH, size.height+30);
	_phaseTF = [self createTextFieldWith:phaseL tag:25 pickerNum:5];
	
	UILabel *addressL = [self.view viewWithTag:6];
	addressL.frame = CGRectMake(0, phaseL.y+phaseL.height+1, SCREEN_WIDTH, size.height+30);
	_addressTV = [self createTextViewWith:addressL tag:26 heightFactor:1.5];
	
	UILabel *companyIntroL = [self.view viewWithTag:7];
	companyIntroL.frame = CGRectMake(0, _addressTV.y+_addressTV.height+1, SCREEN_WIDTH, size.height+30);
	_companyIntroTV = [self createTextViewWith:companyIntroL tag:27 heightFactor:4];
	
	UILabel *advantageL = [self.view viewWithTag:8];
	advantageL.frame = CGRectMake(0, _companyIntroTV.y+_companyIntroTV.height+1, SCREEN_WIDTH, size.height+30);
	_advantageTV = [self createTextViewWith:advantageL tag:28 heightFactor:3];
	
	UILabel *bossL = [self.view viewWithTag:9];
	bossL.frame = CGRectMake(0, _advantageTV.y+_advantageTV.height+1, SCREEN_WIDTH, size.height+30);
	_bossTV = [self createTextViewWith:bossL tag:29 heightFactor:3];
	
	UILabel *teamL = [self.view viewWithTag:10];
	teamL.frame = CGRectMake(0, _bossTV.y+_bossTV.height+1, SCREEN_WIDTH, size.height+30);
	
	UIView *imgWhiteBgView = [[UIView alloc] initWithFrame:CGRectMake(0, teamL.y+teamL.height, SCREEN_WIDTH, 230)];
	imgWhiteBgView.backgroundColor = kWhiteColor;
	[_scrollView addSubview:imgWhiteBgView];
	
	__weak CompanyIntroViewController *weakSelf = self;
	_teamImgBtn = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-20, 200)];
	[_teamImgBtn setImage:IMAGE(@"btn_add_pic")];
	_teamImgBtn.tag = 30;
	[_teamImgBtn addActionWithblock:^{
		[weakSelf picAction:weakSelf.teamImgBtn];
	}];
	[imgWhiteBgView addSubview:_teamImgBtn];
	
	//PickerView相关
	//初始化PickerView相关组件
	_pickerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
	[self.view addSubview:_pickerBgView];
	_pickerBgView.backgroundColor = RGBA(0, 0, 0, 0.2);
	_pickerBgView.hidden = YES;
	
	_companySizeInfoArr = @[@"20人以下", @"20-99人", @"100-500人", @"500-1000人", @"1000人以上"];
	_companySizePicker = [self createPicker];
	
	_phaseInfoArr = @[@"未融资", @"天使轮", @"A轮", @"B轮", @"C轮", @"D轮及以上", @"已上市", @"不需要融资"];
	_phasePicker = [self createPicker];
	
	_pickerToolbgView = [[UIView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, 40)];
	[self.view addSubview:_pickerToolbgView];
	_pickerToolbgView.backgroundColor = UISeparatedColorRGB;
	
	NSArray *arr2 = @[@"取消", @"确定"];
	for (int i = 0; i < arr2.count; i++) {
		UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
		[_pickerToolbgView addSubview:btn];
		[btn setTitle:arr2[i] forState:UIControlStateNormal];
		[btn setTitleColor:kBlackColor forState:UIControlStateNormal];
		btn.titleLabel.font = kUHSystemFontWithSize(12);
		if (i==0) {
			btn.frame = CGRectMake(0, 0, 50, 40);
			[btn addTarget:self action:@selector(pickerRemove) forControlEvents:UIControlEventTouchUpInside];
		}
		else {
			btn.frame = CGRectMake(SCREEN_WIDTH-50, 0, 50, 40);
			[btn addTarget:self action:@selector(priceBtnText) forControlEvents:UIControlEventTouchUpInside];
		}
	}
	UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 39, SCREEN_WIDTH, 1)];
	[_pickerToolbgView addSubview:line];
	line.backgroundColor = kLightGrayColor;
	
	//保存按钮
	UIButton *saveBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, imgWhiteBgView.y+imgWhiteBgView.height+20,  SCREEN_WIDTH-30*2, 40)];
	saveBtn.layer.cornerRadius = saveBtn.height/4;
	[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
	[saveBtn setBackgroundColor:UIMainColorRGB];
	[saveBtn addTarget:self action:@selector(completeAction:) forControlEvents:UIControlEventTouchUpInside];
	[_scrollView addSubview:saveBtn];
	
	_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, saveBtn.y+saveBtn.height+20+64);
}

#pragma mark ==========UIPickerView==========
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pickerView
{
	return 1;
}
//UIPickerViewDataSource中定义的方法，该方法的返回值决定该控件指定列包含多少个列表项
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	if([pickerView isEqual:_companySizePicker]){
		return self.companySizeInfoArr.count;
	}
	else if([pickerView isEqual:_fieldPicker]){
		return self.fieldInfoArr.count;
	}
	else if([pickerView isEqual:_phasePicker]){
		return self.phaseInfoArr.count;
	}
	else {
		return 0;
	}
}
// UIPickerViewDelegate中定义的方法，该方法返回的NSString将作为UIPickerView
// 中指定列和列表项的标题文本
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
	if([pickerView isEqual:_companySizePicker]) {
		return self.companySizeInfoArr[row];
	}
	else if([pickerView isEqual:_fieldPicker]) {
		return self.fieldInfoArr[row];
	}
	else if([pickerView isEqual:_phasePicker]) {
		return self.phaseInfoArr[row];
	}
	else{
		return @"";
	}
}
// 当用户选中UIPickerViewDataSource中指定列和列表项时激发该方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
	/*
	if ([pickerView isEqual:_categoryPicker]) {
		
		[pickerView reloadComponent:1];
		[pickerView reloadComponent:0];
	}
	 */
}

- (void)priceBtnText {
	
	if(_companySizePicker.isHidden == NO)
	{
		UITextField *textField = (UITextField *)[self.view viewWithTag:23];
		textField.text = self.companySizeInfoArr[[_companySizePicker selectedRowInComponent:0]];
		[self pickerRemove];
	}
	else if(_phasePicker.isHidden == NO)
	{
		UITextField *textField = [self.view viewWithTag:25];
		textField.text = self.phaseInfoArr[[_phasePicker selectedRowInComponent:0]];
		[self pickerRemove];
	}
}

- (void)pickerShow:(NSInteger)picker {
	[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
	if(picker == 3){
		_companySizePicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40-54;
			_companySizePicker.y = SH(3)*2-94;
		} completion:^(BOOL finished) {
		}];
	}
	else if(picker == 5){
		_phasePicker.hidden = NO;
		_pickerBgView.hidden = NO;
		[UIView animateWithDuration:0.33 animations:^{
			_pickerToolbgView.y = SH(3)*2-40-54;
			_phasePicker.y = SH(3)*2-94;
		} completion:^(BOOL finished) {
		}];
	}
}
- (void)pickerRemove {
	
	[UIView animateWithDuration:0.33 animations:^{
		_pickerToolbgView.y = 2*SCREEN_HEIGHT;
		_companySizePicker.y = 2*SCREEN_HEIGHT;
		_fieldPicker.y = 2*SCREEN_HEIGHT;
		_phasePicker.y = 2*SCREEN_HEIGHT;
	} completion:^(BOOL finished) {
		_pickerBgView.hidden = YES;
		_companySizePicker.hidden = YES;
		_fieldPicker.hidden = YES;
		_phasePicker.hidden = YES;
	}];
}

- (UIPickerView *)createPicker {
	UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 2*SCREEN_HEIGHT, SCREEN_WIDTH, SH(2.5))];
	[self.view addSubview:picker];
	picker.delegate = self;
	picker.dataSource = self;
	picker.backgroundColor = UISeparatedColorRGB;
	picker.showsSelectionIndicator = YES;
	picker.hidden = YES;
	return picker;
}

- (UILabel *)createLabel:(UILabel *)label text:(NSString *)text {
	
	label.textColor = [UIColor grayColor];
	label.text = text;
	label.font = kUHSystemFontWithSize(15);
	label.backgroundColor = kWhiteColor;
	return label;
}

- (UITextView *)createTextViewWith:(UILabel *)label tag:(NSInteger)tag heightFactor:(CGFloat)heightFactor
{
	UITextView *textView = [[UITextView alloc] init];
	[_scrollView addSubview:textView];
	textView.textColor = [UIColor lightGrayColor];
	textView.font = kUHSystemFontWithSize(14);
	textView.delegate = self;
	[textView scrollRangeToVisible:NSMakeRange(0,1)];
	CGSize signSize = [textView sizeThatFits:CGSizeMake(SCREEN_WIDTH-20-SW(20), MAXFLOAT)];
	textView.frame = CGRectMake(0, label.y+label.height+1, SCREEN_WIDTH, 15+signSize.height*heightFactor);
	textView.textContainerInset = UIEdgeInsetsMake(15, SW(20), 15, 20);//设置页边
	textView.tag = tag;
	textView.text = @"请填写";
	return textView;
}

- (UITextField *)createTextFieldWith:(UILabel *)label tag:(NSInteger)tag pickerNum:(NSInteger)picker
{
	CGSize size = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(15)];
	UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30+size.width, label.y, SCREEN_WIDTH-(50+size.width), size.height+30)];
	[_scrollView addSubview:textField];
	textField.delegate = self;
	textField.textColor = kGrayColor;
	textField.clearButtonMode = UITextFieldViewModeWhileEditing;
	textField.font = kUHSystemFontWithSize(15);
	textField.textAlignment = NSTextAlignmentRight;
	textField.rightViewMode = UITextFieldViewModeAlways;
	textField.tag = tag;
	UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, size.height/2, size.height)];
	textField.rightView = imgV;
	imgV.image = IMAGE(@"arrow_right_grey");
	
	if (picker!=0) {
		UIView *view = [[UIView alloc] initWithFrame:CGRectMake(textField.x, textField.y, textField.width, textField.height)];
		[_scrollView addSubview:view];
		[view addActionWithblock:^{
			NSLog(@"选择器%ld",picker);
			[self pickerShow:picker];
		}];
	}
	return textField;
}

- (void)picAction:(UIView *)sender {
	
	self.imgTag = sender.tag;
	if (sender.tag == 21) {
		self.imgIndex = 0;
	}
	else{
		self.imgIndex = 1;
	}
	NSLog(@"%ld", self.imgTag);
	
	UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择照片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
	
	[alert addAction:[UIAlertAction actionWithTitle:@"从相册中选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSLog(@"从相册中选择");
		
		self.picker.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
		self.picker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.picker.sourceType];
		[self presentViewController:self.picker animated:YES completion:nil];
		
	}]];
	[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
		NSLog(@"拍照");
		
		self.picker.sourceType =  UIImagePickerControllerSourceTypeCamera;
		self.picker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:self.picker.sourceType];
		[self presentViewController:self.picker animated:YES completion:nil];
		
	}]];
	[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
		
	}]];
	[self presentViewController:alert animated:YES completion:nil];
	
}

#pragma mark ==========照相机相册功能==========
/**
 *  配置图片选择器
 */
-(void)createImgPicker {
	self.picker = [[UIImagePickerController alloc]init];
	self.picker.delegate = self;
	self.picker.allowsEditing = YES;
	self.picker.navigationBar.tintColor = [UIColor blackColor];
}

/**
 *  当用户选取完成后调用
 *
 *  @param picker 图片选择器对象
 *  @param info   返回用户所选择的媒体信息
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
	
	NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
	
	// 判断选择的媒体类型是否为图片
	if ([mediaType isEqualToString:@"public.image"]) {
		
		if (picker.sourceType == UIImagePickerControllerSourceTypeCamera){
			
			//如果是 来自照相机的image，那么先保存
			UIImage* original_image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
			UIImageWriteToSavedPhotosAlbum(original_image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
		}
		
		//获得编辑过的图片
		UIImage *image = [[info objectForKey: @"UIImagePickerControllerEditedImage"] copy];
		
		[self updateCover:image];
		
		
		[self dismissViewControllerAnimated:YES completion:nil];
		
	}
}

/**
 *  将图片保存到iPhone本地相册
 *  UIImage *image            图片对象
 *  id completionTarget       响应方法对象
 *  SEL completionSelector    方法
 *  void *contextInfo
 */
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
	
	if (error == nil) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"照片已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
		[alert show];
		
	}else{
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"照片保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
		[alert show];
	}
	
}

//如果这是一个modalViewController，需要dismiss 它发了个cancel消息，必须关闭它
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	[self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark ==========网络请求==========
- (void)updateCover:(UIImage *)img {
	
	AFHTTPSessionManager *afn = [AFHTTPSessionManager manager];
	
	// 请求头
	[afn.requestSerializer setValue:[GetUserDefaule(Token) valueForKey:@"access_token"]forHTTPHeaderField:@"Authorization"];
	NSDictionary *dict = @{
						   @"file[]":@[]
						   };
	
	[MBProgressHUD showHUDAddedTo:self.view animated:YES];
	[afn POST:APIImages parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
		// formData: 专门用于拼接需要上传的数据,在此位置生成一个要上传的数据体
		// 这里的_photoArr是你存放图片的数组
		NSData *imageData = UIImageJPEGRepresentation(img, 0.8);
		
		// 在网络开发中，上传文件时，是文件不允许被覆盖，文件重名
		// 要解决此问题，
		// 可以在上传时使用当前的系统事件作为文件名
		NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
		// 设置时间格式
		[formatter setDateFormat:@"yyyyMMddHHmmss"];
		NSString *dateString = [formatter stringFromDate:[NSDate date]];
		NSString *fileName = [NSString  stringWithFormat:@"%@.jpg", dateString];
		/*
		 *该方法的参数
		 1. appendPartWithFileData：要上传的照片[二进制流]
		 2. name：对应网站上[upload.php中]处理文件的字段（比如upload）
		 3. fileName：要保存在服务器上的文件名
		 4. mimeType：上传的文件的类型
		 */
		[formData appendPartWithFileData:imageData name:@"pic[]" fileName:fileName mimeType:@"image/jpeg"]; //
		
	} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
		id obj = [JWT decodeMessage:responseObject[@"token"]].secret(JWTSecret).algorithmName(@"HS256").decode;
		//        return [obj valueForKey:@"payload"];
		NSArray *imgArr = [[[obj valueForKey:@"payload"] valueForKey:@"data"] valueForKey:@"images"];
		NSLog(@"上传图片 success = %@", imgArr);
		
		//        [self.imgStrArr replaceObjectAtIndex:self.imgTag-31 withObject:responseObject[@"resources"][0]];
		[self.imgStrArr replaceObjectAtIndex:self.imgIndex withObject:imgArr[0]];
		NSLog(@"%@", self.imgStrArr);
		
		[MBProgressHUD hideHUDForView:self.view animated:YES];
		if (self.imgTag == 21) {
			UIButton *imgBtn = (UIButton *)[self.view viewWithTag:self.imgTag];
			[imgBtn setBackgroundImage:img forState:UIControlStateNormal];
		}
		else {
			UIImageView *teamImgView = (UIImageView *)[self.view viewWithTag:self.imgTag];
			[teamImgView setImage:img];
			teamImgView.contentMode = UIViewContentModeScaleAspectFit;
		}
		
	} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
		NSLog(@"上传图片 failure = %@", error);
		[MBProgressHUD hideHUDForView:self.view animated:YES];
		[self presentViewController:[LZCTools AFNErrorAlert:error] animated:YES completion:nil];
	}];
	
}

- (void)completeAction:(UIButton *)sender {
	NSLog(@"完成信息编辑");
	
	NSArray *tfArr = @[self.imgStrArr[0], self.imgStrArr[1], self.companyNameTF.text,
					   self.companySizeTF.text, self.fieldTF.text, self.phaseTF.text,
					   self.addressTV.text, self.companyIntroTV.text, self.advantageTV.text, self.bossTV.text];
	
	for(NSString *str in tfArr)
	{
		if ([NSString isEmpty:str] || [str isEqualToString:@"请填写"])
		{
			[self presentViewController:[LZCTools alertMessage:@"各项内容均不能为空，请填写完成后再提交"] animated:YES completion:nil];
			return;
		}
	}
	NSLog(@"title is %@", self.model.title);
	NSDictionary *paramDict = @{
								@"company_id":self.model.company_id,
								@"title":self.companyNameTF.text,
								@"logo":self.imgStrArr[0],
								@"desc":self.companyIntroTV.text,
								@"address":self.addressTV.text,
								@"latitude":@"",
								@"longitude":@"",
								@"team_img":self.imgStrArr[1],
								@"industry_field":self.fieldTF.text,
								@"company_size":self.companySizeTF.text,
								@"boss":self.bossTV.text,
								@"development":self.phaseTF.text,
								@"advantage":self.advantageTV.text,
								};
	
	[[NetworkTool sharedTool] requestWithName:@"更新企业信息" URLString:APIUpdateCompany parameters:paramDict method:@"POST" callBack:^(id responseObject) {
		NSString *resultState = responseObject[@"data"][@"status"];
		if ([resultState integerValue] == 1) {
			UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"保存成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
			[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
				[self.navigationController popViewControllerAnimated:YES];
			}]];
			[self presentViewController:alert animated:YES completion:nil];
		}
	}];
}

- (void)getCompanyInfo
{
	[[NetworkTool sharedTool] requestWithName:@"获取企业信息" URLString:APIQueryCompany parameters:nil method:@"POST" callBack:^(id responseObject) {
		NSDictionary *dict = responseObject[@"data"];
		if ([dict isKindOfClass:[NSDictionary class]]) {
			CompanyInfo *model = [[CompanyInfo alloc] init];
			[model setValuesForKeysWithDictionary:dict];
			self.model = model;
		}
		else
		{
			NSLog(@"is not a dict");
		}
		
	}];
}

- (void)setModel:(CompanyInfo *)model
{
	if (_model != model) {
		_model = model;
	}
	if (model.logo.length!=0) {
		[self.logo sd_setBackgroundImageWithURL:[NSURL URLWithString:model.logo] forState:UIControlStateNormal];
		[self.imgStrArr replaceObjectAtIndex:0 withObject:model.logo];
	}
	self.companyNameTF.text = model.title;
	self.companySizeTF.text = model.company_size;
	self.fieldTF.text = model.industry_field;
	self.phaseTF.text = model.development;
	if (model.address.length!=0) {
		self.addressTV.text = model.address;
	}
	if (model.desc.length!=0) {
		self.companyIntroTV.text = model.desc;
	}
	if (model.advantage.length!=0) {
		self.advantageTV.text = model.advantage;
	}
	if (model.boss.length!=0) {
		self.bossTV.text = model.boss;
	}
	if (model.team_img.length!=0) {
		[self.teamImgBtn sd_setImageWithURL:[NSURL URLWithString:model.team_img] placeholderImage:IMAGE(@"placeHolder")];
		self.teamImgBtn.contentMode = UIViewContentModeScaleAspectFit;
		[self.imgStrArr replaceObjectAtIndex:1 withObject:model.team_img];
	}
}

- (NSMutableArray *)imgStrArr
{
	if (!_imgStrArr) {
		_imgStrArr = [[NSMutableArray alloc] init];
		[_imgStrArr addObject:@""];
		[_imgStrArr addObject:@""];
	}
	return _imgStrArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
